package org.hegang.design.first.factorypattern;

import org.hegang.design.common.CommonFields;
import org.hegang.design.first.factorypattern.shapeimpl.Circle;
import org.hegang.design.first.factorypattern.shapeimpl.Rectangle;
import org.hegang.design.first.factorypattern.shapeimpl.Square;

/**
 * @ClassName ShapeFactory
 * @Describe: 形状工厂类,这种方式属于简单方式
 * @Author: gang.he
 * @Date: Created in 22:38 2019/6/27
 * Modified By:
 * Version V1.0
 */
public class ShapeFactory {
    /**
     * 实现一
     *
     * 通过shapeType获取形状类型对象
     * @param shapeType
     * @return
     */
    public Shape getShape(String shapeType){
        if(shapeType == null){
            return null;
        }
        if(shapeType.trim().equalsIgnoreCase(CommonFields.RECTANGLE)){
            return new Rectangle();
        }else if(shapeType.trim().equalsIgnoreCase(CommonFields.SQUARE)){
            return new Square();
        }else if(shapeType.trim().equalsIgnoreCase(CommonFields.CIRCLE)){
            return new Circle();
        }
        return null;
    }

    /**
     * 实现二
     * @return
     */
    public static Shape getCircle(){
        return new Circle();
    }

    public static Shape getRectangle(){
        return new Rectangle();
    }
}
